Research
Security News
Quasar RAT Disguised as an npm Package for Detecting Vulnerabilities in Ethereum Smart Contracts
Socket researchers uncover a malicious npm package posing as a tool for detecting vulnerabilities in Etherium smart contracts.
A minimalistic class system designed for flexibility, functional programming. Inspired from Golang's Struct concept.
Motivation:
new-struct
is small and simple. All it does is composing functions and objects.new
and this
keywords. So, you'll never have to fix scopes.new-struct
and structs.How does a struct look?
var Struct = require('new-struct')
var Animal = Struct({
sleep: sleep,
speak: speak
})
module.exports = Animal;
function sleep (animal) { console.log('zzzz'); }
function speak (animal, text) {
console.log('%s says %s', animal.name, text);
}
Check out Usage and examples for more info about it.
$ npm install new-struct
A new struct is defined by an object of methods:
Struct = require('new-struct')
Animal = Struct({
sleep: sleep,
run: run,
speak: speak
})
function sleep (animal) {
console.log('zzz');
}
function speak (animal, sound) {
console.log('%s says %s', animal.name, sound)
}
function run (animal) {
console.log('%s is running', animal.name)
}
To create a an instance of the Animal
struct, just call it with an object.
this
and new
keywords are not needed, everything is just functions.
dongdong = Animal({ name: 'dongdong' })
blackbear = Animal({ name: 'blackbear' })
dongdong.name
// => 'dong dong'
dongdong.run()
// dongdong is running
blackbear.sleep()
// blackbear is sleeping
It doesn't support constructors, but constructor-like factory functions are easy to implement:
function NewAnimal (name, age) {
return Animal({ name: name, age: age })
}
Note that you can attach your constructor as a static method. So, you could have such a module:
Animal = Struct({
New: New,
run: run,
speak: speak
})
module.exports = Animal;
function New (name, age) {
return Animal({ name: name, age: age })
}
function speak (animal, sound) {
console.log('%s says %s', animal.name, sound)
}
function run (animal) {
console.log('%s is running', animal.name)
}
This will allow other modules requiring this have more flexibility:
Animal = require('./animal')
// You can either create using constructor:
Animal.New('dong dong', 13)
// Or calling the constructor itself:
Animal({ name: 'dong dong', age: 13 })
// You can also access the methods of Animal:
Animal.methods.run({ name: 'black bear' })
// will output: black bear is running
You can create structs that mixes other ones:
Animal = require('./animal')
Cat = Struct(Animal, {
meow: meow
})
function meow (cat) {
Animal.methods.speak(cat, 'meooww')
}
Notice that each struct has a property called methods
that keeps all the functions passed to it, including the ones derived from other structs.
See the tests and examples for more info, or create issues & send pull requests to improve the documentation.
FAQs
This package name is not currently in use, but was formerly occupied by a popular package. To avoid malicious use, npm is hanging on to the package name, but loosely, and we'll probably give it to you if you want it.
We found that new-struct demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Research
Security News
Socket researchers uncover a malicious npm package posing as a tool for detecting vulnerabilities in Etherium smart contracts.
Security News
Research
A supply chain attack on Rspack's npm packages injected cryptomining malware, potentially impacting thousands of developers.
Research
Security News
Socket researchers discovered a malware campaign on npm delivering the Skuld infostealer via typosquatted packages, exposing sensitive data.